Release 10.1A: OpenEdge Data Management:
DataServer for Microsoft SQL Server
Error handling
One common data entry error is attempting to add a duplicate record; that is, trying to create a record using a unique key that already exists in the database. Suppose, for example, that a user tries to add a
customerwithcust-num=1(wherecust-numis a unique key), but acustomerrecord with thiscust-numvalue already exists. The attempt fails and an error is generated.When this type of error occurs, the 4GL run time engine tries to resolve it by working back through the procedure, looking at each block header until the closest block with the error-handling property is found, and then undoing and retrying the block. (See OpenEdge Development: Progress 4GL Handbook for more information about error handling.) However, because the DataServer is accessing a non-OpenEdge data source, duplicate-key errors can not be detected until the end of a transaction block. Therefore, if an error occurs in a subtransaction, it is not detected until the end of the entire transaction block and default error handling must be performed for the entire transaction block.
The following example illustrates OpenEdge database and DataServer error handling:
This procedure displays the following screen, in which the user is prompted to enter data into the
cust-numfield and then thestatefield:
![]()
Suppose that the user enters an existing state (for example, NH) while the 4GL is processing the
DOblock. When this duplicate-key entry occurs for an OpenEdge database, the 4GL returns control to theDOblock, displays a message that the record exists, and reprompts the user for a state abbreviation.However, with the DataServer, if a duplicate key entry occurs in the
DOblock, the 4GL returns control to theREPEATblock rather than theDOblock. As a result, the procedure reprompts the user for a customer number after the inner transaction completes:
![]()
If you use
NO–ERRORto do your own error handling, you must account for the fact that an MSS data source creates or updates a record later than an OpenEdge database does. For example, the following code does not trap data source errors, because the requests to perform the operations have not yet been sent to the data source:
The
VALIDATEstatement causes the DataServer to send requests to your MSS data source, so incorporate it into your error-handling technique, as in the following example:
This code returns data-source errors after the
VALIDATEstatement.Another difference in behavior occurs when two users simultaneously attempt to create records with duplicate keys. An OpenEdge database raises an error immediately, but the data source raises an error after the first transaction commits and only if the second transaction does not roll back. To avoid this difference, either change the scope of the transaction so that it completes more quickly or make the key nonunique and enforce uniqueness at the application level. Another technique is to use a
RELEASEorVALIDATEstatement when you check for the key’s uniqueness.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |